document.getElementById('btn-get-dom').addEventListener('click', async () => {
  // TODO: sidney mock
  // const response = await sendContentMsgAsync('getSudoKuData');
  // sudokuNums = response.result.sudokuNums;
  // console.warn(JSON.stringify(sudokuNums));


  // TODO: sidney mock
  sudoku.sudokuNums = [
    [1, 0, 0,   2, 0, 4,  0, 0, 0],
    [8, 2, 6,   5, 3, 0,  0, 0, 7],
    [4, 9, 0,   7, 0, 0,  0, 0, 0],

    [9, 1, 0,   4, 0, 0,  6, 0, 0],
    [3, 0, 8,   1, 7, 6,  0, 0, 0],
    [6, 0, 0,   9, 5, 0,  0, 1, 0],
    
    [0, 6, 1,   8, 0, 0,  3, 0, 5],
    [0, 8, 4,   3, 0, 5,  0, 0, 0],
    [5, 3, 9,   6, 0, 7,  0, 0, 8]
  ];

  // sudoku.sudokuNums = [
    // [1, 0, 0, 2, 0, 4, 0, 0, 0],
    // [8, 2, 6, 5, 3, 0, 0, 0, 7],
    // [4, 9, 0, 7, 0, 0, 0, 0, 0],
    // [9, 1, 0, 4, 0, 0, 6, 0, 0],
    // [3, 0, 8, 1, 7, 6, 0, 0, 0],
    // [6, 0, 0, 9, 5, 0, 0, 1, 0],
    // [0, 6, 1, 8, 0, 0, 3, 0, 5],
    // [0, 8, 4, 3, 0, 5, 0, 0, 0],
    // [5, 3, 9, 6, 0, 7, 0, 0, 8]
  // ];

  sudoku.sudokuObjs = sudoku.sudokuNums.map(a => {
    let row = a.map(b => {
      let item = { num: 0, isStable: false, expect: [] };
      if (b) {
        item.num = b;
        item.isStable = true;
      }
      return item;
    });
    return row;
  });

  sudoku.refreshSudoku();
});

document.getElementById('btn-calc').addEventListener('click', async () => {
  sudoku.calc();
});


$("#btn-show").click(async () => {
  const response = await sendContentMsgAsync('show');
  console.warn(response);
});

async function sendContentMsgAsync(method, data) {
  const tabs = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
  let tab = tabs[0];
  // const [tab] = await chrome.tabs.query({ active: true });

  let msgCode = `content-msg-${method}`;
  const response = await chrome.tabs.sendMessage(tab.id, { msgCode, data });
  return response;
}